const fs = require('fs');
const app = require('j7/app');
const utils = require('j7/utils');
const bcutils = require('j7/bcutils');
const event = require('j7/event');
const config = require('j7/config');
const bchelper = require('common/bchelper');
const common = require('./common');

const startTokenId = 6240603010000001;
const endTokenId = 6240603010003001;

//const startTokenId = 6240603010010001;
//const endTokenId = 6240603010013001;

function mint() {
  let seqId = 1;
  const outJson = [];
  for (let tokenId = startTokenId; tokenId <= endTokenId; ++tokenId) {
    const outItem = {};
    outItem['address'] = '';
    outItem['type'] = 'hero';
    outItem['item_id'] = common.heroList[utils.randRange(0, common.heroList.length)];
    outItem['level'] = 1;
    outItem['quality'] = 1;
    outItem['token_id'] = tokenId;
    outJson.push(outItem);
    ++seqId;
  }
  const totalNum = 2168;
  const highHeroNum = 200;
  {
    let num = 0;
    while (true) {
      const rndIdx = utils.randRange(startTokenId, startTokenId + totalNum - 1) - startTokenId;
      if (outJson[rndIdx]['quality'] != 2) {
        outJson[rndIdx]['quality'] = 2;
        ++num;
      }
      if (num >= highHeroNum) {
        break;
      }
    }
  }
  {
    let highNum = 0;
    let highestTokenId = 0;
    outJson.forEach((val) => {
      if (val.quality > 1) {
        highNum++;
        if (val.token_id > highestTokenId) {
          highestTokenId = val.token_id;
        }
      }
      if (val.quality <0 ||
          val.quality > 2) {
        console.log('error');
      }
    });
    console.log('highNum', highNum, 'highestTokenId', highestTokenId);
  }
  const airDropDate = '24060301';
  fs.writeFileSync(
    `../bin_dev/web3tools/config/second_airdrops/${airDropDate}.airdrop.json`,
    utils.prettyJsonEncode(outJson));
}

mint();
